package datamining;

import java.io.IOException;
import java.io.FileReader;
import java.io.BufferedReader;
import java.lang.String;


public class Input {
    private String path;
    private int numberOfLines = 0;

    public Input(String path)
    {
        this.path = path;
        numberOfLines = 0;
    }

    public String[] ReadFile() throws IOException
    {

        FileReader fr = new FileReader(path);
        BufferedReader textReader = new BufferedReader(fr);

        int LineCount = numberOfLines();

        String[] textData = new String[LineCount];
        for (int i = 0; i <LineCount; ++i)
        {
            textData[i] = textReader.readLine();
        }
        
        textReader.close();
        return textData;
    }

    public int numberOfLines() throws IOException
    {
        if (numberOfLines != 0)
        {
            return numberOfLines;
        }
        else
        {
            FileReader fr = new FileReader(path);
            BufferedReader lineCount = new BufferedReader(fr);
            String aLine;
            int numberOfLines = 0;
            while (( aLine = lineCount.readLine()) != null)
            {
                numberOfLines++;
            }
            lineCount.close();
            return numberOfLines;
        }
    }


}
